<?php
namespace Admin\Controller;

use Common\Controller\AdminbaseController;
class XiaoquController extends AdminbaseController{
	

	
	function _initialize() {
		parent::_initialize();
		$this->db = D("Xiaoqu");

	}
	
	function index(){





		if(I("get.are")){

			$map['are']=I("get.are");

		}
		if(I("get.shop_id")){

			$map['shop_id']=I("get.shop_id");

		}

		if(I("get.keyword")){

			$map['name']=array("like","%".trim(I("get.keyword"))."%");

		}




		$list=$this->db->order ( "pinyin  asc ")->where($map)->select();
		

		$this->assign("list",$list);
		
		$this->display();
	}
	

	
	
	function add(){

		if(IS_POST){
			cookie("add_xiaoqu_group",$_POST[are]);
			cookie("add_xiaoqu_shop",$_POST[shop_id]);

			$_POST["pinyin"]=pinyin($_POST["name"]);

			if ($this->db->create($_POST)) {
				if ($this->db->add()!==false) {


					$this->success("添加成功！");
				} else {
					$this->error("添加失败！");
				}
			} else {
				$this->error($this->db->getError());
			}
		}else{

			$data["are"]=cookie("add_xiaoqu_group");
			$data["shop_id"]=cookie("add_xiaoqu_shop");

			$this->assign("data",$data);

			$this->display("form");
		}
		}

	
	function edit(){
		
		
		if(IS_POST){

			$_POST["pinyin"]=pinyin($_POST["name"]);

			if ($this->db->create($_POST)) {
				
				if ($this->db->save()!==false) {

					$this->success("保存成功！");
				} else {
					$this->error("保存失败！");
				}
			} else {
				$this->error($this->db->getError());
			}
		
		}else{
	
		$id= intval(I("get.id"));
		if(!$id){
			$this->error("缺少参数！");
		}

		$r=$this->db->where("id=$id")->find();
		$this->assign("edit",true);
		$this->assign("data",$r);
		$this->display("form");
		}
	}

	function  chuli(){

		$ids=I("post.ids");

		$shop_id=I("post.shop_id");

		if(!$shop_id){
			$this->error("请选择负责的提货站!");
		}




		$this->db->where(array("id"=>array("in",$ids)))->save(array("shop_id"=>$shop_id));



		$this->success("成功");



	}

	
	
	}